package com.hxkcloud.patient.aerotel.database;

import android.content.ContentValues;
import android.net.Uri;
import android.provider.BaseColumns;


import com.hxkcloud.patient.aerotel.domain.health.AerotelECGPdu;
import com.hxkcloud.patient.aerotel.provider.HDContentProvider;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by daipengfei on 16/3/27.
 */
public class ECGTable implements BaseColumns {

    public final static String CONTENT_TYPE = "hdc/ecg";
    public final static String COLLECTION_CONTENT_TYPE = "hdc/ecgs";

    public final static String TABLE_NAME = "t_ecgs";

    public final static String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "(_id INTEGER PRIMARY KEY AUTOINCREMENT, device TEXT,sn TEXT,btmac TEXT, ecg_file TEXT, created_date TEXT,state INTEGER DEFAULT 0);";

    public final static Uri CONTENT_URI = Uri.parse("content://" + HDContentProvider.AUTHORITY + "/ecgs");

    public final static String DEVICE = "device";
    public final static String DEVICE_SN = "sn";
    public final static String DEVICE_BTMAC = "btmac";
    public final static String CREATED_DATE = "created_date";
    public final static String ECG_FILE = "ecg_file";
    public final static String UPLOAD_STATE = "state";

    public static final String DEFAULT_ORDERBY = "_id DESC";

    public static Map<String, String> PROJECTION_MAP = new HashMap<>();

    static {
        PROJECTION_MAP.put(_ID, _ID);
        PROJECTION_MAP.put(DEVICE, DEVICE);
        PROJECTION_MAP.put(DEVICE_SN, DEVICE_SN);
        PROJECTION_MAP.put(DEVICE_BTMAC, DEVICE_BTMAC);
        PROJECTION_MAP.put(CREATED_DATE, CREATED_DATE);
        PROJECTION_MAP.put(ECG_FILE, ECG_FILE);
        PROJECTION_MAP.put(UPLOAD_STATE, UPLOAD_STATE);
    }

    public static ContentValues getContentValues(AerotelECGPdu ecg) {
        ContentValues cv = new ContentValues();
        cv.put(DEVICE, ecg.devicename);
        cv.put(DEVICE_SN, ecg.devicesn);
        cv.put(DEVICE_BTMAC, ecg.devicebtmac);
        cv.put(CREATED_DATE, ecg.createdDate);
        cv.put(ECG_FILE, ecg.file);
        cv.put(UPLOAD_STATE,ecg.state);
        return cv;
    }
}
